<template>
  <div class="app-container">
    <el-tabs v-model="status" type="card" @tab-click="handleClickStatus">
      <el-tab-pane name="-1">
        <span slot="label">
          <i class="el-icon-s-order"></i> 全部退费单
        </span>
      </el-tab-pane>
      <el-tab-pane name="1">
        <span slot="label">
          <i class="el-icon-document"></i> 退款中
        </span>
      </el-tab-pane>
      <el-tab-pane name="2">
        <span slot="label">
          <i class="el-icon-document"></i> 拒绝退款
        </span>
      </el-tab-pane>
      <el-tab-pane name="3">
        <span slot="label">
          <i class="el-icon-circle-close"></i> 退款成功
        </span>
      </el-tab-pane>
      <el-tab-pane name="4">
        <span slot="label">
          <i class="el-icon-circle-close"></i> 退款失败
        </span>
      </el-tab-pane>
    </el-tabs>

    <el-form
      :model="queryParams"
      ref="queryForm"
      :rules="queryRules"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          show-word-limit
          clearable
          class="inputClass"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车架号" prop="vin">
        <el-input
          v-model="queryParams.vin"
          placeholder="请输入车架号"
          maxlength="17"
          show-word-limit
          clearable
          class="inputClass"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车型名称" prop="modelName">
        <!--<el-input-->
          <!--v-model="queryParams.modelName"-->
          <!--placeholder="请输入车型名称"-->
          <!--maxlength="40"-->
          <!--show-word-limit-->
          <!--clearable-->
          <!--class="inputClass"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->

        <el-select
          v-model="queryParams.modelName"
          placeholder="请选择"
          filterable
          clearable
          style="width: 240px"
          @change="onSelectChange"
        >
          <el-option
            v-for="item in carModelList"
            :key="item.modelCode"
            :label="item.modelName"
            :value="item.modelName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          maxlength="40"
          show-word-limit
          clearable
          class="inputClass"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="softwareName">
        <el-input
          v-model="queryParams.softwareName"
          placeholder="请输入商品名称"
          maxlength="40"
          show-word-limit
          clearable
          class="inputClass"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="购买规格" prop="softwareSpec">-->
        <!--<el-input-->
          <!--v-model="queryParams.softwareSpec"-->
          <!--placeholder="请输入购买规格"-->
          <!--maxlength="40"-->
          <!--show-word-limit-->
          <!--clearable-->
          <!--class="inputClass"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="订单来源" prop="orderSource">
        <el-select v-model="queryParams.orderSource" placeholder="请选择订单来源" clearable>
          <el-option
            v-for="dict in dict.type.order_source"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式" prop="paymentType">
        <el-select
          v-model="queryParams.paymentType"
          placeholder="请选择支付方式"
          clearable
        >
          <el-option
            v-for="dict in dict.type.pay_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item label="退款申请来源" prop="refundsSource">
        <el-select
          v-model="queryParams.refundsSource"
          placeholder="请选择退款申请来源"
          clearable
        >
          <el-option
            v-for="dict in dict.type.order_source"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>-->
      <el-form-item label="激活状态" prop="activeStatus">
        <el-select v-model="queryParams.activeStatus" placeholder="请选择激活状态" clearable>
          <el-option
            v-for="dict in dict.type.order_active_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="退款原因" prop="refundReason">
        <el-input
          v-model="queryParams.refundReason"
          placeholder="请输入退款原因"
          clearable
          class="inputClass"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退款申请时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="退款状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择退款状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.order_refund_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>-->
      <!-- <el-form-item label="退款单号" prop="refundTradeNo">
        <el-input
          v-model="queryParams.refundTradeNo"
          placeholder="请输入退款单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['shop:refund:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="tableColumns"></right-toolbar>
    </el-row>

    <el-table
      ref="tables"
      v-loading="loading"
      :data="refundList"
      @selection-change="handleSelectionChange"
      :default-sort="defaultSort"
      @sort-change="handleSortChange"
    >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column
        label="订单号"
        align="center"
        prop="orderNo"
        key="orderNo"
        v-if="tableColumns[0].visible"
      />

      <el-table-column
        label="车架号"
        align="center"
        prop="vin"
        key="vin"
        v-if="tableColumns[1].visible"
      />
      <el-table-column
        label="车型名称"
        align="center"
        prop="modelName"
        key="modelName"
        v-if="tableColumns[2].visible"
      />
      <el-table-column
        label="商品名称"
        align="center"
        prop="softwareName"
        key="softwareName"
        v-if="tableColumns[3].visible"
      />
      <el-table-column
        label="支付方式"
        align="center"
        prop="paymentType"
        key="paymentType"
        v-if="tableColumns[4].visible"
      >
        <template slot-scope="scope">
          <span v-if="!scope.row.paymentType || scope.row.paymentType.length == 0">-</span>
          <dict-tag v-else :options="dict.type.pay_type" :value="item" v-for="item in scope.row.paymentType.split(',')" :key="item"/>
        </template>
      </el-table-column>
      <el-table-column
        label="软件包功能项"
        align="center"
        prop="softwareFunction"
        key="softwareFunction"
        v-if="tableColumns[5].visible"
      >
        <template
          slot-scope="scope"
          v-if="scope.row.softwareFunction"
        >{{ scope.row.softwareFunction }}</template>
      </el-table-column>
      <el-table-column
        label="购买规格"
        align="center"
        prop="softwareSpec"
        key="softwareSpec"
        v-if="tableColumns[6].visible"
      />
      <el-table-column
        label="用户ID"
        align="center"
        prop="userId"
        key="userId"
        v-if="tableColumns[7].visible"
      />
      <el-table-column
        label="购买人昵称"
        align="center"
        prop="userName"
        key="userName"
        v-if="tableColumns[8].visible"
      />
      <el-table-column
        label="支付流水号"
        align="center"
        prop="transactionId"
        key="transactionId"
        v-if="tableColumns[9].visible"
      />
      <el-table-column
        label="已付额度"
        align="center"
        prop="payAmount"
        key="payAmount"
        v-if="tableColumns[10].visible"
      >
        <template slot-scope="scope">
          <el-tag color="red" style="color:#fff;" v-if="scope.row.payAmount == 0">{{ scope.row.payAmount }}</el-tag>
          <span v-else-if="scope.row.paymentType == 'DAP'">{{ parseInt(scope.row.payAmount) }}</span>
          <span v-else>￥{{ scope.row.payAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="订单来源"
        align="center"
        prop="orderSource"
        key="orderSource"
        v-if="tableColumns[11].visible"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_source" :value="scope.row.orderSource"/>
        </template>
      </el-table-column>
      <el-table-column
        label="退款状态"
        align="center"
        prop="isPay"
        key="isPay"
        min-width="150"
        v-if="tableColumns[12].visible"
      >
        <template slot-scope="scope">
          <!--<div class="grid-content flex-content">-->
            <!--激活状态：-->
            <!--<dict-tag :options="dict.type.order_active_status" :value="scope.row.activeStatus"/>-->
          <!--</div>-->

          <!--<div class="grid-content flex-content">-->
            <!--开票状态：-->
            <!--<dict-tag :options="dict.type.order_is_makeout" :value="scope.row.makroutStatus"/>-->
          <!--</div>-->

          <div class="grid-content flex-content">
            <dict-tag :options="dict.type.order_refund_status" :value="scope.row.status"/>
          </div>
        </template>
      </el-table-column>

      <!-- <el-table-column label="退款状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.order_refund_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>-->
      <el-table-column
        label="退款额度"
        align="center"
        prop="refundAmount"
        key="refundAmount"
        v-if="tableColumns[13].visible"
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.refundAmount == 0">-</el-tag>
          <span v-else-if="scope.row.paymentType == 'DAP'">{{ parseInt(scope.row.refundAmount) }}</span>
          <span v-else>￥{{ scope.row.refundAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="退款单号"
        align="center"
        prop="refundTradeNo"
        key="refundTradeNo"
        v-if="tableColumns[14].visible"
      />
      <el-table-column
        label="退款原因"
        align="center"
        prop="refundReason"
        key="refundReason"
        :show-overflow-tooltip="true"
        v-if="tableColumns[15].visible"
      />
      <!--<el-table-column label="退款申请来源" align="center" prop="refundSource" >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.refund_source"
            :value="scope.row.refundSource"
          />
        </template>
      </el-table-column>-->
      <el-table-column
        label="审核不通过原因"
        align="center"
        prop="refuseRefundReason"
        key="refuseRefundReason"
        :show-overflow-tooltip="true"
        v-if="tableColumns[16].visible"
      />
      <el-table-column
        label="退款失败原因(支付中心)"
        align="center"
        prop="refundFailReason"
        key="refundFailReason"
        v-if="tableColumns[17].visible"
      />
      <el-table-column
        label="是否支持未激活7天无理由退款"
        align="center"
        prop="noReasonRefund7d"
        key="noReasonRefund7d"
        v-if="tableColumns[18].visible"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_support_refund" :value="scope.row.noReasonRefund7d"/>
        </template>
      </el-table-column>
      <el-table-column
        label="退款申请时间/创建时间"
        align="center"
        prop="createDate"
        key="createDate"
        width="110"
        sortable="custom"
        :sort-orders="['descending', 'ascending']"
        v-if="tableColumns[19].visible"
      ></el-table-column>
      <!-- <el-table-column
        label="创建时间"
        align="center"
        prop="createDate"
        width="110"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>-->
      <el-table-column
        label="最后更新时间"
        align="center"
        prop="lastUpdateDate"
        key="lastUpdateDate"
        v-if="tableColumns[20].visible"
        width="110"
      ></el-table-column>
      <el-table-column
        label="最后更新人"
        align="center"
        prop="lastUpdateBy"
        key="lastUpdateBy"
        v-if="tableColumns[21].visible"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['shop:refund:edit']"
            v-if="scope.row.status == 6"
          >审核</el-button>
          <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-info"-->
            <!--@click="handleCheck(scope.row)"-->
            <!--v-hasPermi="['shop:refund:get']"-->
          <!--&gt;查看</el-button>-->
          <el-dropdown
                size="mini"
                @command="(command) => handleCommand(command, scope.row)"
              >
                <span class="el-dropdown-link">
                  <i class="el-icon-d-arrow-right el-icon--right"></i>更多
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item
                    command="handleStatus"
                    icon="el-icon-refresh"
                    v-if="scope.row.status =='1'"
                  >更新支付中心状态</el-dropdown-item>
                  <el-dropdown-item
                    command="verifyDetail"
                    icon="el-icon-circle-check"
                     v-if="scope.row.status!='0'"
                  >审核详情</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--退费审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px" @submit.native.prevent>
        <el-form-item :label="form.paymentType == 'DAP'?'退款积分':'退款金额'" prop="refundAmount">
          <el-input v-model="form.refundAmount" :disabled="true"/>
        </el-form-item>
        <el-form-item label="拒绝退款原因" prop="refuseRefundReason">
          <el-input v-model="form.refuseRefundReason" type="textarea" placeholder="请输入拒绝退款原因"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonRefuseLoading" type="danger" @click="refuseRefunds">拒绝退款</el-button>
        <el-button :loading="buttonAgreeLoading" type="success" @click="agreeRefunds">同意退款</el-button>
      </div>
    </el-dialog>

    <!-- 审核详情 -->
    <el-dialog :title="titlefund" :visible.sync="openfund" width="500px" append-to-body>
      <el-form ref="form" :model="viewRow" :rules="rules" label-width="140px" @submit.native.prevent>
        <el-form-item label="审核人" prop="dictType">
          <el-input v-model="viewRow.verifyUser" :disabled="true"/>
        </el-form-item>
        <el-form-item label="审核不通过的原因" prop="remark">
          <el-input v-model="viewRow.refuseRefundReason" type="textarea" :disabled="true"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelFu">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRefund,
  getRefund,
  delRefund,
  addRefund,
  updateRefund,
  agreeRefund,
  refuseRefund,
  refreshRefund
} from "@/api/shop/refund";
import {
  getModelListUrl,
} from "@/api/statistics/index.js";

export default {
  name: "Refund",
  dicts: [
    "order_refund_status",
    "order_active_status",
    "order_source",
    "order_is_makeout",
    "is_support_refund",
    "pay_type",
  ],
  data() {
    return {
      // table列筛选
      tableColumns: [
        { key: 0, label: `订单号`, visible: true },
        { key: 1, label: `车架号`, visible: true },
        { key: 2, label: `车型名称`, visible: true },
        { key: 3, label: `商品名称`, visible: true },
        { key: 4, label: `支付状态`, visible: true },
        { key: 5, label: `软件包功能项`, visible: true },
        { key: 6, label: `购买规格`, visible: true },
        { key: 7, label: `用户ID`, visible: true },
        { key: 8, label: `购买人昵称`, visible: true },
        { key: 9, label: `支付流水号`, visible: true },
        { key: 10, label: `已付额度`, visible: true },
        { key: 11, label: `订单来源`, visible: true },
        { key: 12, label: `退款状态`, visible: true },
        { key: 13, label: `退款额度`, visible: true },
        { key: 14, label: `退款单号`, visible: true },
        { key: 15, label: `退款原因`, visible: true },
        { key: 16, label: `审核不通过原因`, visible: true },
        { key: 17, label: `退款失败原因(支付中心)`, visible: true },
        { key: 18, label: `是否支持未激活7天无理由退款`, visible: true },
        { key: 19, label: `退款申请时间/创建时间`, visible: true },
        { key: 20, label: `最后更新时间`, visible: true },
        { key: 21, label: `最后更新人`, visible: true }
      ],
      // 按钮loading
      buttonLoading: false,
      buttonRefuseLoading: false,
      buttonAgreeLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      viewRow: {},
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退费单表格数据
      refundList: [],
      // 弹出层标题
      title: "",
      titlefund: "",
      // 是否显示弹出层
      open: false,
      openfund: false,
      // 默认排序
      defaultSort: { prop: "createDate", order: "descending" },
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // orderItemId: undefined,
        status: undefined,
        refundTradeNo: undefined,
        refundDate: undefined,
        refundReason: undefined,
        activeStatus: undefined,
        orderSource: undefined,
        softwareSpec: undefined,
        orderNo: undefined,
        vin: undefined,
        userId: undefined,
        refundsSource: undefined,
        modelName: undefined,
        softwareName: undefined,
        startCreateDate: undefined,
        endCreateDate: undefined,
        ids: undefined,
        orderByColumn: "createDate",
        isAsc: "descending"
      },
      //  查询参数校验
      queryRules: {
        orderNo: [
          {
            validator: (rule, value, callback) => {
              if (value.length > 0 && !new RegExp(/^\d{0,40}$/).test(value)) {
                this.queryParams.orderNo = undefined;
                callback(new Error("请输入正确的订单号"));
              } else if (value.length > 40) {
                callback(new Error("订单号的长度不能超过40"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        // userId: [
        //   {
        //     validator: (rule, value, callback) => {
        //       if (value.length > 0 && !new RegExp(/^\d{0,10}$/).test(value)) {
        //         this.queryParams.userId = undefined;
        //         callback(new Error("请输入正确的用户ID"));
        //       } else if (value.length > 10) {
        //         callback(new Error("用户Id的长度不能超过10"));
        //       } else {
        //         callback();
        //       }
        //     },
        //     trigger: "blur"
        //   }
        // ],
        vin: [
          {
            validator: (rule, value, callback) => {
              if (
                value.length > 0 &&
                !new RegExp(/^[A-HJ-NPR-Z\d]{0,17}$/).test(value)
              ) {
                this.queryParams.vin = undefined;
                callback(new Error("请输入正确的VIN"));
              } else if (value.length > 17) {
                callback(new Error("VIN的长度不能超过17"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ]
      },
      status: "-1",
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        refuseRefundReason: [
          { required: true, message: "拒绝退款原因不能为空", trigger: "blur" }
        ]
      },
      carModelList: [],
    };
  },
  created() {
    this.getList();
  },
  async mounted() {
    await this.getCarModelList();
  },
  methods: {
    /**
     * 获取车型数据
     */
    getCarModelList() {
      return new Promise((resolve) => {
        getModelListUrl().then((res) => {
          if (res.data) {
            this.carModelList = res.data;
          }
          resolve(true);
        });
      });
    },
    /** 查询退费单列表 */
    getList() {
      this.loading = true;
      this.queryParams.ids = undefined;
      if (this.dateRange != "" && this.dateRange != null) {
        this.queryParams.startCreateDate = this.dateRange[0];
        this.queryParams.endCreateDate = this.dateRange[1];
      } else {
        this.queryParams.startCreateDate = undefined;
        this.queryParams.endCreateDate = undefined;
      }

      listRefund(this.queryParams).then(response => {
        this.refundList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /**
     * 修改选项
     */
    onSelectChange(e) {
      if(!this.queryParams.modelName){
        this.queryParams.modelName = undefined;
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    handleClickStatus(tab, event) {
      this.queryParams.pageNum = 1;
      this.status = tab.name;
      this.queryParams.status = this.status != "-1" ? this.status : null;
      this.getList();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        // orderId: undefined,
        // orderItemId: undefined,
        status: undefined,
        refundAmount: undefined,
        refundTradeNo: undefined,
        refundReason: undefined,
        refuseRefundReason: undefined,
        createDate: undefined,
        createBy: undefined,
        lastUpdateDate: undefined,
        lastUpdateBy: undefined,
        deleteFlag: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.ids = undefined;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.queryParams.ids = undefined;
      this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.queryParams.ids = undefined;
      this.getList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getRefund(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.form.refundAmount = this.form.paymentType == 'DAP' ? Number(response.data.refundAmount): response.data.refundAmount;
        this.open = true;
        this.title = "退款审核";
      });
    },

    //拒绝退款
    refuseRefunds() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonRefuseLoading = true;
          refuseRefund({
            id: this.form.id,
            paymentType: this.form.paymentType,
            refuseRefundReason: this.form.refuseRefundReason
          })
            .then(response => {
              this.$modal.msgSuccess("拒绝退款成功");
              this.open = false;
              this.getList();
            })
            .finally(() => {
              this.buttonRefuseLoading = false;
            });
        }
      });
    },

    //同意退款
    agreeRefunds() {
      this.buttonAgreeLoading = true;
      agreeRefund({
        id: this.form.id,
        paymentType: this.form.paymentType
      })
        .then(response => {
          this.$modal.msgSuccess("同意退款成功");
          this.open = false;
          this.getList();
        })
        .finally(() => {
          this.buttonAgreeLoading = false;
        });
    },

    /**
     * 查看详情
     */
    handleCheck(row) {
      this.$router.push({
        path: "/shop/refund/detail",
        query: {
          id: row.id
        }
      });
    },

    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleStatus":
          this.handleStatus(row);
          break;
        case "verifyDetail":
          this.verifyDetail(row);
          break;
        default:
          break;
      }
    },

    handleStatus(row) {
      refreshRefund(row.id).then((res) => {
        if(res.data.status == 1){
           this.$modal.msgSuccess("该笔退费单，还在退款中，请前往“退款中”页签查看");
        }else if(res.data.status == 3){
           this.$modal.msgSuccess("该笔退费单，已退款成功，请前往“退款成功”页签查看");
        }
        else if(res.data.status == 4){
            this.$modal.msgSuccess("该笔退费单，退款失败，请前往“退款失败”页签查看");
        }
      });
    },

    verifyDetail(row) {
      this.openfund = true;
      this.titlefund = "审核详情";
      this.viewRow = row;
    },

    // 取消按钮
    cancelFu() {
      this.openfund = false;
      this.reset();
    },

    /** 导出按钮操作 */
    handleExport() {
      this.queryParams.ids = undefined;
      if (this.ids.length > 0) {
        if (this.ids.length > 1000) {
          this.$message.error("勾选导出的数据不能超过一千条！");
          return false;
        }
        let selectionIds = "";
        this.ids.forEach(id => {
          selectionIds += id + ",";
        });
        if (selectionIds.length > 0) {
          selectionIds = selectionIds.substring(0, selectionIds.length - 1);
        }
        this.queryParams.ids = selectionIds;
      }
      this.download(
        "shop/refund/export",
        {
          ...this.queryParams
        },
        `refund_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
<style scoped>
.inputClass {
}
/* element-ui input style overload */
::v-deep .inputClass > input {
  padding-right: 70px;
}
</style>
